package cn.hfjava.kz.common;

import lombok.Data;
import lombok.experimental.Accessors;

/**
 * 统一JSON响应结果
 * @param <T> 参数化类型
 */
@Data
@Accessors(chain = true)
public class R<T> {
    private int code;
    private String message;
    private T data;

    public static <T> R<T> success(T data){
        return new R<T>()
                .setCode(200)
                .setMessage("SUCCESS").setData(data);
    }


    public static <T> R<T> success(String message){
        return new R<T>()
                .setCode(200)
                .setMessage(message);
    }


    public static <T> R<T> fail(String message){
        return new R<T>()
                .setCode(400)
                .setMessage(message);
    }

    public static <T> R<T> fail(int code,String message){
        return new R<T>()
                .setCode(code)
                .setMessage(message);
    }

    public static <T> R<T> error(){
        return new R<T>()
                .setCode(500)
                .setMessage("系统繁忙，请稍后重试!");
    }

    public static <T> R<T> error(String message){
        return new R<T>()
                .setCode(500)
                .setMessage(message);
    }
}
